package com.zmx.base.service;

import com.zmx.base.repository.BaseServicePhoneRepository;
import com.zmx.common.common.invocation.InvocationInfoProxy;
import com.zmx.common.common.utils.SignUtils;
import com.zmx.user.api.MemberApi;
import com.zmx.user.dto.MemberDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 公共实现类
 * @ClassName: BaseService
 * @Author zhaomxr
 * @Date 2022-01-12 10:39
 */
@Slf4j
@Service
public class BaseService {

    @Value("${sign.secretKey}")
    private String sign_secretKey;
    @Autowired
    private MemberApi memberApi;
    @Autowired
    private BaseServicePhoneRepository baseServicePhoneRepository;

    /**
     * 获取签名
     * @param timeStamp
     * @return
     */
    public String getSign(String timeStamp) {
        Long memberId = Long.valueOf(InvocationInfoProxy.getUserId());
        MemberDto memberDTO = memberApi.findByMemberId(memberId);
        Map<String, String> params = new HashMap<String, String>(3);
        params.put("openId", memberDTO.getOpenid());
        params.put("name", memberDTO.getName());
        params.put("timeStamp", timeStamp);
        String sign = SignUtils.getSign(params, sign_secretKey);
        System.out.println("签名sign为：" + sign);
        return sign;
    }

    public String getServicePhone() {
        return baseServicePhoneRepository.findServicePhone();
    }
}
